﻿using parkMonitor.language;
using parkMonitor.model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace parkMonitor.viewModel.devInfoPanel {
	/// <summary>设备报警数量面板Control</summary>
	public class ComInfoCountPanelVM : ObservableCollection<DevPanelItemVM> {
		public ComInfoCountPanelVM() {
			normal = new ComInfoCountPanelItemVM() { DevStatus = ComInfoStatus.Normal };
			warn = new ComInfoCountPanelItemVM() { DevStatus = ComInfoStatus.Warning };
			error = new ComInfoCountPanelItemVM() { DevStatus = ComInfoStatus.Error };

			Add(normal);
			Add(warn);
			Add(error);
		}

		public ComInfoCountPanelVM(int normalNum, int warnNum, int errNum):this() {
			setValue(normalNum, warnNum, errNum);
		}

		public void setValue(int normalNum, int warnNum, int errNum) {
			normal.Num = normalNum;
			warn.Num = warnNum;
			error.Num = errNum;
		}
		
		/// <summary>正常</summary>
		public ComInfoCountPanelItemVM normal { get; private set; }
		
		/// <summary>警告</summary>
		public ComInfoCountPanelItemVM warn { get; private set; }
		
		/// <summary>错误</summary>
		public ComInfoCountPanelItemVM error { get; private set; }
	}

	/// <summary>设备报警数量面板ViewModel</summary>
	public class ComInfoCountPanelItemVM : DevPanelItemVM, INotifyPropertyChanged {
		public ComInfoCountPanelItemVM() {
			DevStatus = ComInfoStatus.Normal;
			Num = 0;
		}

		ComInfoStatus _DevStatus = ComInfoStatus.Normal;
		public ComInfoStatus DevStatus {
			get { return _DevStatus; }
			set {
				_DevStatus = value;
				switch(value) {
				case ComInfoStatus.Normal:Name = Language.ins.normal;break;
				case ComInfoStatus.Warning:Name = Language.ins.warning; break;
				case ComInfoStatus.Error:Name = Language.ins.error; break;
				}
				updateColor();
				FirePropertyChanged("DevStatus");
			}
		}

		int _Num = 0;
		public int Num {
			get { return _Num; }
			set {
				_Num = value;
				Info = value + Language.ins.aFrew;
				updateColor();
				FirePropertyChanged("Num");
			}
		}

		private void updateColor() {
			ColorByStatus = _Num > 0 ? _DevStatus : ComInfoStatus.Normal;
		}
	}
}
